import time
import sys
import json
sys.path.append(r'.')
from DrissionPage import ChromiumPage


def load_param_datas_from_file(file_path):
    with open(file_path, "r", encoding='utf-8') as f:
        json_file_datas = json.loads(f.read())    # load的传入参数为字符串类型
        return json_file_datas
def down_json_file():
    json_file_datas = load_param_datas_from_file('item_tag_down.data.json')
    port = json_file_datas['port']
    url = json_file_datas['url']
    itemId = json_file_datas['itemId']
    save_path = json_file_datas['savePath']
    page = ChromiumPage(addr_or_opts= '127.0.0.1:' + str(port))
    page.get(url)
    # 等待页面加载
    page.wait.load_start()
    # 滚动到某个已获取到的元素
    # <a class="sycm-traced-download-text ">
    # <i class="anticon anticon-download oui-canary-icon oui-canary-icon-download"></i>下载</a>
    down_link = page.ele('tag:a@@text():下载')
    mission = down_link.click.to_download(save_path, itemId)  # 点击一个会触发下载的链接，同时设置下载路径和文件名
    mission.wait()  # 等待下载结束

down_json_file()





